public class MyQueue {
    public static void main(String[] args) {

    }
    static  class ListNode{
        private int val;
        private ListNode prev;
        private ListNode next;
        public ListNode(int val){
            this.val = val;
        }

    }
    private ListNode front;//对头
    private ListNode rear;
    private int usdsize;
    public void offer(int x){
        ListNode node=new ListNode(x);
        if(front==null){
            front=rear=node;
        }
        else {
            //头插法

            node.next=front;
            front.prev=node;
            front=node;
            
        }
        usdsize++;
    }
    public int poll(){

        if(front==null){
            usdsize--;
            return-1;
        }
        //只有一个节点
        int ret=rear.val;
        if(front==rear){
            front=null;
            rear=null;
            usdsize--;
            return ret;



        }
        else{
            rear=rear.prev;
            rear.next=null;
            usdsize--;
        }
        return ret;
    }


}
